/**
 * 签到页面
 * author:yinht
 * date:2017年5月24日09:52:42
 */
define(function(require, exports, module) {
			var wechat = require("wechat");

			var changepwd = {
					/**
					 * bindEvent 页面事件
					 */
					bindEvent: function() {
						//返回
						$("#return_changepwd").unbind().on("click", function() {
							window.location.href = "#/index/my";
						});
						$("#sure").unbind().on("click", function() {
							//$("#error_m").removeClass("hidden");
							changepwd.sendParam("");
						});
					},
					/**
					 * 进行页面路由监听配置
					 * 
					 */
					bindRout: function() {
						//公共页面监听路由
						Path.map("#home").to(function() {
							//返回首页
							common.loadPage({
								pageUrl: "html/my.html",
								reload: true,
								from: "right"
							});
						});
						Path.map("#/index/:page_name").to(function() {
							console.log(this.params["page_name"]);
							var page_name = this.params["page_name"];
							var nextPageFrom = "left"; //从右边过来
							//记录状态
							common.loadPage({
								pageUrl: "html/" + page_name + ".html",
								reload: true,
								from: nextPageFrom
							});
						});
						Path.listen();
					},
		/**
		 * 页面数据加载
		 */
		sendParam: function() {
				var pk_user = window.localStorage.getItem("pk_user");
				var pwd = $("#ypwd").val();
				var newpwd = $("#newpwd").val();
				var oldpwd = $("#ypwd").val();
				var pwdagain = $("#pwdagain").val();
				var reg = /^[\x21-\x7E]{6,20}$/;
				var r = newpwd.match(reg);
				if(newpwd != pwdagain) {
					common.showTip({
						time: 3000,
						content: "两次输入的密码不一致！",
						callback: function() {
							//common.showTip({content:"我已经关闭"});
						}
					});
					return;
				} else if(!oldpwd) {
					common.showTip({
						time: 3000,
						content: "原密码不能为空！",
						callback: function() {
							//common.showTip({content:"我已经关闭"});
						}
					});
					return;
				} else if(r == null) {
					common.showTip({
						time: 3000,
						content: "新密码必须由6-20位英文字母、数字或符号组成！",
						callback: function() {
							//common.showTip({content:"我已经关闭"});
						}
					});
					return;
				}
				var param = {
					"pk_user": pk_user,
					oldpwd: pwd,
					newpwd: newpwd
				}
				common.loadData({
					url: "/service/RRTPubServlet?method=amendPwd", //"/UMPPubServlet?method=getWxUserInfo",
					param: param,
					successCallBack: changepwd.getUserInfoCallBack, //回调函数
					dataSource: "getUserInfo",
					cache: false
				});
			},
			getUserInfoCallBack: function(json) {
				console.log(JSON.stringify(json));
				if(json.status == "0") {
					common.showTip({
						time: 3000,
						content: "修改密码成功！",
						callback: function() {
							//common.showTip({content:"我已经关闭"});
						}
					});
					window.history.back(-1);
				} else {
					common.showTip({
						content: json.message
					});
				}
			},
			/**
			 * each page init mothed
			 */
			initialize: function() {

				//this.loadData();
				//事件绑定
				this.bindEvent();
				//路由绑定
				this.bindRout();
			}
		};

		module.exports = changepwd;
		});